var e = require("../../utils/http.js"),
  t = (require("../../utils/util.js"), require("../../utils/api.js")),
  n =
    (require("../../utils/md5.js"),
    require("../../utils/language/switchLanguage.js"));
Page({
  data: {
    content: "",
    type: "",
    winHeight: 0,
    isActive: !1,
    productNo: null,
    is_show: !1,
    payMent: "wxSmallPay",
    isAgreeCandidate: 0,
    showPlay: !0,
    totalAmount: 10,
  },
  onLoad: function (e) {
    wx.setStorageSync("language", 0),
      this.initLanguage(),
      this.setData({ height: wx.getSystemInfoSync().windowHeight - 108 }),
      null != e.showPlay && this.setData({ showPlay: !1 }),
      this.setData({ skey: e.skey, openId: requireMiniProgram().getOpenId() }),
      wx.setStorageSync("skey", e.skey),
      this.getOpenId();
  },
  initLanguage: function () {
    var e = n.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: e, languageType: wx.getStorageSync("language") });
  },
  getOpenId: function () {
    var n = this,
      a = {
        appNo: "wx393d60d93f70599c",
        openId: this.data.openId,
        configType: 1,
        loginType: 2,
        accessToken: this.data.skey,
      };
    e.threeWayLogin(a).then(function (e) {
      if (null == e.uid)
        return (
          t.showMsg(n.data._t["登录过期，请重新登录"]),
          void wx.navigateTo({
            url: "/pages/mine-index/login/index?redirectUrl=".concat(
              encodeURIComponent("plugin://order/index-page"),
              "&type=4",
            ),
          })
        );
      n.setData({
        museumMerchant: e.museumMerchant,
        isTeam: e.isTeam,
        teamType: e.teamType,
      }),
        wx.setStorageSync("token", e.token),
        wx.setStorageSync("openId", e.openId),
        wx.setStorageSync("uid", e.uid),
        wx.setStorageSync("telphoneNumber", e.contactsPhone),
        wx.setStorageSync("museumMerchant", e.museumMerchant),
        wx.setStorageSync("merchantNo", e.museumMerchant.merchantNo),
        n.getTicketConfig();
    });
  },
  getTicketConfig: function () {
    var t = this;
    e.getGuideTicketConfig({ sourceType: 21 }).then(function (e) {
      0 == e.code &&
        t.setData({
          productNo: e.data.config[0].productNo,
          content: e.data.config[0].bookingNotes,
          refundNotes: e.data.config[0].refundNotes,
          totalAmount: e.data.config[0].price,
        });
    });
  },
  get_height: function (e) {
    var t = this;
    setTimeout(function () {
      wx.createSelectorQuery()
        .in(t)
        .select(e)
        .boundingClientRect(function (e) {
          var n = e.height;
          e.width;
          n < t.data.height && t.setData({ isActive: !0 });
        })
        .exec();
    }, 200);
  },
  scrollToLower: function (e) {
    this.setData({ isActive: !0 });
  },
  ConfirmPament: function () {
    this.data.isActive
      ? this.setData({ is_show: !0 })
      : t.showMsg(this.data._t["请先阅读预约须知"]);
  },
  subForm: t.throttle(function () {
    this.setData({ is_show: !1 }), this.CreateOrder();
  }),
  CreateOrder: function () {
    var n = this,
      a = {
        museumOrderUsers: [],
        orderQuantity: 1,
        productNo: this.data.productNo,
      },
      i = {
        data: JSON.stringify(a),
        orderType: 4,
        sourceType: 21,
        payType: 4,
        tradeType: this.data.payMent,
        payConfigType: 4,
      },
      o = t.encryptBASE64(JSON.stringify(i)),
      r = { sign: t.autograph(o), signData: o };
    wx.showLoading({ title: "支付发起中..." }),
      e
        .CreateGuideOrder(r)
        .then(function (e) {
          if (
            (n.setData({
              touristList: [],
              ConfirmPhone: "",
              totalPrice: 0,
              date: "",
              showDate: "",
              currentdate: null,
              currentTime: null,
              ticketTypeList: [],
            }),
            wx.hideLoading(),
            1 != e.orderStatus)
          )
            if (0 == e.orderStatus && "wxSmallPay" == n.data.payMent)
              n.wechatPay(e.data);
            else {
              e.data.qrcode;
              wx.switchTab({ url: "/pages/tour-index/index" });
            }
          else
            wx.navigateTo({
              url: "plugin-private://wx393d60d93f70599c/pages/audioGuideOrder/index",
            });
        })
        .catch(function (e) {
          wx.hideLoading();
        });
  },
  wechatPay: function (e) {
    var t = this;
    requireMiniProgram()
      .requestPayment(e)
      .then(function (e) {
        return "requestPayment:ok" == e.errMsg
          ? (wx.showLoading({ title: t.data._t["支付处理中"] + "..." }),
            void setTimeout(function () {
              wx.hideLoading(),
                wx.navigateTo({
                  url: "plugin-private://wx393d60d93f70599c/pages/audioGuideOrder/index",
                });
            }, 1e3))
          : void wx.switchTab({ url: "/pages/tour-index/index" });
      })
      .catch(function (e) {
        if ("requestPayment:fail cancel" != e.errMsg)
          return "requestPayment:fail cancel" != e.errMsg &&
            "requestPayment:fail" != e.errMsg
            ? (wx.showModal({
                title: t.data._t["通知"],
                showCancel: !1,
                content: t.data._t["调起支付失败，请稍后重试"] + "...",
                confirmText: t.data._t["确认"],
              }),
              void setTimeout(function () {
                wx.hideLoading(),
                  wx.switchTab({ url: "/pages/tour-index/index" });
              }, 1e3))
            : void 0;
        wx.switchTab({ url: "/pages/tour-index/index" });
      });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
});
